// pages/Index/shopActive/invitation/index.js
const controller = require('../../../controllers/controllerIndex').controller

Page({

  data: {
    pageNumber:1,
    invitationList:[],
    lastPage:false,

  },
  onLoad: function (options) {
  },
  onShow: function () {
    this.getInvitationList(true)
  },
  onReachBottom(){
    console.log(2);
    if(this.data.lastPage)return
    this.getInvitationList()
  },
  getInvitationList(isFirst = false){
    if(isFirst){
      this.setData({
        pageNumber:1,
        invitationList:[]
      })
    }
    let pageNumber=this.data.pageNumber
    let invitationList=this.data.invitationList
    let value={
      shopId:wx.getStorageSync('shopId'),
      sessionId:wx.getStorageSync('token'),
      pageNumber,
      pageSize:20
    }
    pageNumber++
    controller.invitationShopPage(value).then(res=>{
      invitationList=invitationList.concat(res.data.list)
      this.setData({
        lastPage:res.data.lastPage,
        invitationList,
        pageNumber
      })
    })
  },
  toInvitationDetail(e){
    console.log(e);
    let invitationId = e.currentTarget.dataset.invitationid
    wx.navigateTo({
      url: './invitation_detail/invitation_detail?invitationId='+invitationId
    })
  },
  toInvitationSend(e){
    let item = e.currentTarget.dataset.item
    wx.navigateTo({
      url: './invitation_send/invitation_send?invitationId='+item.id+'&giveNum='+item.giveNum+'&totalNum='+item.totalNum
    })
  },
  delete(e){
    let invitationId = e.currentTarget.dataset.invitationid
    let value={
      shopId:wx.getStorageSync('shopId'),
      sessionId:wx.getStorageSync('token'),
      invitationId,
    }
    controller.invitationDelete(value).then(res=>{
      this.getInvitationList(true)
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})